from django.db import models
from django.conf import settings


# Create your models here.


class Coupon(models.Model):
    NOT_START = 0
    START_ISSUE = 1
    END_ISSUE = 2

    STATUS_CHOICES = (
        (NOT_START, '未开始'),
        (START_ISSUE, '发放中'),
        (END_ISSUE, '已结束')
    )
    status = models.PositiveSmallIntegerField(verbose_name='状态', choices=STATUS_CHOICES, default=NOT_START)
    title = models.CharField(verbose_name='优惠券名称', max_length=150)
    money = models.PositiveIntegerField(verbose_name='抵扣金额', default=200)
    total_quantity = models.PositiveIntegerField(verbose_name="总数量")
    issued_quantity = models.PositiveIntegerField(verbose_name="发放数量", default=0)

    start_time = models.DateTimeField(verbose_name='发放开始时间')
    end_time = models.DateTimeField(verbose_name='发放结束时间')

    notes = models.CharField(verbose_name="备注", max_length=500, null=True, blank=True)
    user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name='创建者', on_delete=models.PROTECT, blank=True)
    delete = models.BooleanField(verbose_name='是否删除', default=False)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)

    class Meta:
        db_table = 'coupon'
        verbose_name = '优惠卷'
        ordering = ('-id',)


class CouponCeleryTask(models.Model):
    coupon = models.ForeignKey(Coupon, verbose_name='优惠卷', on_delete=models.PROTECT)
    # 定时任务
    start_issue_coupon_task_id = models.CharField(verbose_name='开始发放优惠卷celery任务ID', max_length=64)
    end_issue_coupon_task_id = models.CharField(verbose_name='结束发放优惠卷celery任务ID', max_length=64)

    class Meta:
        db_table = 'coupon_celery_task'
        verbose_name = '优惠卷定时任务id'
        ordering = ('-id',)


